package test;

public class print1 {
    public static void main(String[] args) {
        System.out.println("================Byte=============");
        byte by=1;
        byte by2=1;
        Byte b=10;
        Byte b2=10;
        System.out.println((b==b2));//true
        System.out.println((b.equals(b2)));//true
        System.out.println(by==by2);


        System.out.println("================Short=============");
        Short s=10;
        Short s2=10;
        Short s3=133;
        Short s4=133;
        System.out.println((s==s2)+","+(s3==s4));//true,false
        System.out.println(s.equals(s2) + "," + s3.equals(s4));//true,true

        System.out.println("================Integer=============");
        Integer age = 10;
        Integer age2 = 10;
        Integer age3 = 133;
        Integer age4 = 133;
        Integer age5 = new Integer(10);
        System.out.println((age == age2) + "," + (age3 == age4));//true,false
        System.out.println(age.equals(age2) + "," + age3.equals(age4));//true,true
        System.out.println(age == age5);//false：new每次都创建一个对象，但是Integer不new的时候在缓存范围内都是一个对象
        System.out.println(age5.equals(age));//true

        System.out.println("================Long=============");
        Long l = 10L;
        Long l2 = 10L;
        Long l3 = 133L;
        Long l4 = 133L;
        System.out.println((l == l2) + "," + (l3 == l4));//true,false
        System.out.println(l.equals(l2) + "," + l3.equals(l4));//true,true

        System.out.println("================Float=============");
        Float f = 10f;
        Float f2 = 10f;
        Float f3 = 133f;
        Float f4 = 133f;
        System.out.println((f == f2) + "," + (f3 == f4));//false,false
        System.out.println(f.equals(f2) + "," + f3.equals(f4));//true,true

        System.out.println("================Double=============");
        Double num = 10d;
        Double num2 = 10d;
        Double num3 = 133d;
        Double num4 = 133d;
        System.out.println((num == num2) + "," + (num3 == num4));//false,false
        System.out.println(num.equals(num2) + "," + num3.equals(num4));//true,true

        System.out.println("=================Byte,Short,Integer,Long,相同值之间的对比=============");
        System.out.println(b.equals(age));//false;Byte的equals方法首先判断是否为Byte类型，如果不是就返回false，是的话再比较值相同的话就true
        System.out.println(age.equals(age4));//false；Byte的equals方法首先判断是否为Byte类型，不是所以返回的是false
        System.out.println(s4.equals(age4));//false
        System.out.println(age.equals(l));//false

        System.out.println("=================float和double");
        float fl=0.1f;
        double db=1.0/10;
        System.out.println(fl);//0.1
        System.out.println(db);//0.1
//        最好完全避免使用浮点数进行比较，因为会精度丢失，如果想要进行计算然后比较就可以使用BigDecimal 数据工具类进行比较。
        System.out.println(fl==db);//false
        float dl1=231212121212f;
        float dl2=dl1+1;
        System.out.println(dl1);//2.31212122E11
        System.out.println(dl2);//2.31212122E11
        System.out.println(dl1==dl2);//true
    }
}
/*
执行结果：
================Byte=============
true
true
true
================Short=============
true,false
true,true
================Integer=============
true,false
true,true
================Long=============
true,false
true,true
================Float=============
false,false
true,true
================Double=============
false,false
true,true
=================Byte,Short,Integer,Long,相同值之间的对比=============
false
false
false
false
=================float和double
0.1
0.1
false
2.31212122E11
2.31212122E11
true
 */